import { ExtIdTuple, INTEGER_PG, VARCHAR_PG, VARCHAR255_PG } from "~/db.pg";
import { Creatable, ExtIntro } from "~/extend";
import { ExtOwner } from "@/stream-user/core.define";
import { ENUM_MEDIA } from "./core.define";
import { RefTonOrderMedia } from "@/river-ton/schema.order";
import { RefVoucherMedia } from "@/river-voucher/schema.voucher";

/** 在线图像的分组 */
export type MediaGroup = ExtIdTuple &
  ExtOwner &
  ExtIntro & {
    joinMediaList?: Media[];
  };

/** 在线图像
 * @FileBrower File:Blob（浏览器） => Formdata:Blob
 * @FileNode File:Buffer（Node:readFileSync） => new Blob([buffer])
 * @Blob 二进制数据（Node、浏览器）核心容器
 */
export type Media = ExtIdTuple &
  ExtOwner &
  ExtIntro &
  Creatable & {
    type: ENUM_MEDIA;
    host: VARCHAR255_PG;
    path: VARCHAR_PG;

    /** bytes */
    size: INTEGER_PG;
    mime: VARCHAR255_PG;

    /** 提供给客户端的临时资源地址 */
    withURL?: string;
  } & {
    refMediaGroupId: MediaGroup["id"];
    justMediaGroup?: MediaGroup;
  } & {
    joinRefTonOrderMediaList?: RefTonOrderMedia[]; // 订单
    joinRefVoucherMediaList?: RefVoucherMedia[]; // 财务记录
  };
